<template>

 	<div class="layui-layout layui-layout-admin" >
 	  <div class="adminnav1">
        <Pagetop></Pagetop>
      </div>
      <div class="adminnav2">
       	<Secondnav urlname="news"></Secondnav>
      </div>

      <!-- 主体内容 -->
      <div class="layui-body kedou-admin" id="LAY_app_body app">
	    <div class="layadmin-tabsbody-item layui-show">
	    	<div class="pagelist">
	    		<div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
					  <legend>资讯留言</legend>
					</fieldset>
		      	</div>

		        <div class="layui-card-body">
			        <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex" :fbtn="btn"></Tables>
		        </div>
	        </div>
	    </div>
	  </div>

	</div>
</template>
<script>
	import Pagetop from '../common/pagetop.vue'
	import Secondnav from '../common/secondnav.vue'
	import Tables from '../common/tables.vue'
	import Search from '../common/search.vue'
	export default {
	  name: 'memberlist',
	  components: {Pagetop,Secondnav,Tables,Search},
	  data () {
	    return {
	        pdate:[], //表头
	    	res:"", //内容
	    	totalRows:"",//总数量
	    	curindex:0, //页数
	    	btn:[],//按钮
	    	searchArr:[],//搜索
	    	isShow:false,
	    	seapram:''
	    }
	  },
	  mounted(){
	  	this.getdate();
     	this.getsearch();
	  },
	  methods: {
      getdate:function(){
        var _this=this;
        var url="/advert/aapi/v1.9/information"
        if(_this.seapram){
          var dates={
            size:pageSize,
            pageSize:pageSize,
            pageNumber:0
          }
          var res=_this.seapram;
          for(var i=0;i<res.length;i++){
            dates[res[i].key]=res[i].val;
          }

        }else{
          var dates={
            size:pageSize,
            page:this.curindex,
            sort:'createAt,DESC'
          }
          }
            //alert(url+"//"+JSON.stringify(dates))
        ajaxRequest(url,'GET','json',dates,function(ret,err){
          //alert(url+"//"+JSON.stringify(ret))
          var arr=[];
          arr[0]=[
             {field: 'accountId', title: '用户ID',}
            ,{field: 'accountName', title: '用户名称',}
            ,{field: 'message', title: '留言内容',}
            ,{field: 'newsId', title: '回复内容',templet:function(d){
               var str="";
               var arr=d.informationVMList
               for(var i=0;i<arr.length;i++){
                 str=str+arr[i].message+","
               }
               return str;
            }}
            ,{field: 'deep', title: '状态',templet:function(d){
                if(d.type=='UNAUDITED'){
                  return '未审核'
                }
                else if(d.type=='AUDIT_PASS'){
                  return '审核通过'
                }
                else{
                  return '审核不通过'
                }
             }}
            ,{field: 'createAt', title: '留言时间',templet:function(d){return FormatDate(d.createAt)}}
            ,{field: 'right',title: '操作', fixed:'right',templet:function(d){
              var  str='<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">回复</a>';
              if(d.type=='UNAUDITED'){
                str=str+'<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="enable">通过</a>';
                str=str+'<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">不通过</a>';
              }
              return str;
            }}
          ];
          _this.pdate=arr;
          _this.res=ret.data.list;
          _this.totalRows=ret.data.totalRows;
          _this.curindex=ret.data.page+1;
        })
      },
      getsearch:function(){
        var arr=[];
        this.searchArr=arr;
      },
      page:function(index,obj){
        //alert(JSON,stringify(obj))
        this.curindex=index;
        this.getdate();

      },
      sousuo:function(pram){
        //alert(JSON.stringify(pram))
        this.seapram=pram;
        this.res='';
        this.totalRows='';
        this.curindex='';
        this.getdate();
      },
    screens:function(){
      return screen();
    },
    enableInfo:function(data){
    	var _this = this;
    	var url = "/advert/aapi/v1.9/information/updateType?auditStatus=AUDIT_PASS&id="+data.id;
    	ajaxRequest(url,'put','json','',function(ret,err){
    		layer.msg("操作成功");
    		setTimeout(function(){
    		  	_this.getdate();
          },1000)
    	})
    },
    delInfo:function(data){
    	var _this = this;
    	var url = "/advert/aapi/v1.9/information/updateType?auditStatus=AUDIT_FAILED&id="+data.id;
    	ajaxRequest(url,'put','json','',function(ret,err){
    		layer.msg("操作成功");
    		setTimeout(function(){
    		  	_this.getdate();
          },1000)
    	})
    },
    editInfo:function(data){
    	var _this = this;
      layer.prompt({
        formType: 2,
        value: '',
        title: '请输入回复内容'
      }, function(value, index, elem){
        var dates={
          "informationId":data.id,
          "message": value,
          "newsId":data.newsId
        }
        var url = "/advert/aapi/v1.9/information";
        ajaxRequest(url,'POST','json',dates,function(ret,err){
        	layer.msg("操作成功");
        	setTimeout(function(){
              layer.close(index);
        	  	_this.getdate();
            },1000)
        })

      });
    }
  },
  updated:function(){
  	this.isShow = true;
	layui.use('form', function(){
	  var form = layui.form;
	  form.render();
	});
  },
}
</script>
<style scoped>
/**/
</style>
